<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category    ZendX
 * @package     ZendX_MooTools
 * @subpackage  View
 * @copyright   Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license     http://framework.zend.com/license/new-bsd     New BSD License
 * @version     $Id:
 */


/**
 * @see Zend_Json
 */
require_once "Zend/Json.php";


/**
 * MooTools  Global Class holding constants and static convienience methods.
 *
 * @package    ZendX_MooTools
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class ZendX_MooTools
{
     /**
     * Current default supported MooTools library version with ZendX_MooTools
     * 
     * @const string
     */
    const DEFAULT_MOOTOOLS_VERSION = "1.2.4";
    
    
    /**
     * Currently supported MooTools moore library version with ZendX_MooTools
     *
     * @const string
     */
    const DEFAULT_MOORE_VERSION = "1.2.4.4";
    
    /**
     * Url CDN BASE
     * 
     * @const string Base path to CDN
     */
    const CDN_BASE_GOOGLE = 'http://ajax.googleapis.com/ajax/libs/';
    
    /**
     * Url SSL CDN BASE
     * 
     * @const string Base path to CDN
     */
    const CDN_BASE_GOOGLE_SSL = 'https://ajax.googleapis.com/ajax/libs/';
    
  
    
     /**
     * @const string
     */
    const CDN_SUBFOLDER_MOOTOOLS = 'mootools/';
    
    /**
     * Always uses compressed version, because this is assumed to be the use case
     * in production enviroment. An uncompressed version has to included manually.
     *
     * @const string File path after base and version
     */
    const CDN_MOOTOOLS_PATH_GOOGLE = '/mootools-yui-compressed.js';
    
    
   /**
     * Which parts of the the MooTools library should be rendered on echo'ing
     * the MooTools library to the View. The constants act as bit-mask. This
     * way the MooTools autogenerated code can be refactored based on personal needs.
     *
     * @see ZendX_MooTools_Helper_MooTools::setRenderMode
     * @const Integer
     */
    const RENDER_LIBRARY            = 1;
    const RENDER_SOURCES            = 2;
    const RENDER_STYLESHEETS        = 4;
    const RENDER_JAVASCRIPT         = 8;
    const RENDER_MOOTOOLS_ON_LOAD   = 16;
    const RENDER_MOOTOOLS_DOM_READY = 32;
    const RENDER_ALL                = 255;
    
    /**
     * MooTools-enable a view instance
     * 
     * @param  Zend_View_Interface $view 
     * @return void
     */
    public static function enableView(Zend_View_Interface $view)
    {
        if (false === $view->getPluginLoader('helper')->getPaths('ZendX_MooTools_View_Helper')) {
            $view->addHelperPath('ZendX/MooTools/View/Helper', 'ZendX_MooTools_View_Helper');
        }
    }
    
    
	/**
     * Encode Json that may include javascript expressions.
     *
     * Take care of using the Zend_Json_Encoder to alleviate problems with the json_encode
     * magic key mechanism as of now.
     *
     * @see Zend_Json::encode
     * @param  mixed $value
     * @return mixed
     */
    public static function encodeJson($value)
    {
        if(!class_exists('Zend_Json')) {
            /**
             * @see Zend_Json
             */
            require_once "Zend/Json.php";
        }
        return Zend_Json::encode($value, false, array('enableJsonExprFinder' => true));
    }
}